package com.zcf.gameController.gameUtils;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zcf.gameController.WebSocketBull;
import com.zcf.pojo.ClubUser;
import com.zcf.pojo.Game;
import com.zcf.pojo.Game_club;
import com.zcf.pojo.Msg;
import com.zcf.pojo.PumpingLog;
import com.zcf.pojo.RoomParam;
import com.zcf.pojo.RoomRecord;
import com.zcf.pojo.RoomsParam;
import com.zcf.pojo.User;
import com.zcf.pojo.UserBean;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;

/**
 * Created with IDEA
 * author:ZhaoQ
 * className:斗地主游戏逻辑类
 * Date:2019/2/12
 * Time:10:36
 */
public class gameLogic {
	private static WebSocketBull ws;
	private Integer card;

	/*
	 *@Author:ZhaoQi
	 *@methodName:创建房间
	 *@Params:
	 *@Description:
	 *@Return:
	 *@Date:2019/2/12
	 */
	public static Object InitializeRoom(Map<String, RoomsParam> rooms, JSONObject jsonObject) {
		Map<String, Integer> roomtype = new HashMap<>();
		roomtype.put("gameType", (Integer) jsonObject.get("gameType"));//游戏玩法
		roomtype.put("points", (Integer) jsonObject.get("points"));//底分
		roomtype.put("num", (Integer) jsonObject.get("num"));//局数
		roomtype.put("starttype", (Integer)jsonObject.get("starttype"));//开始类型
		roomtype.put("maxz", (Integer)jsonObject.get("maxz"));//最大抢庄
		roomtype.put("personnum", (Integer)jsonObject.get("personnum"));//人数
		roomtype.put("roomnum",  (int)((Math.random()*4+5)*100000)+1);//房间号
		roomtype.put("double", (Integer)jsonObject.get("double"));//翻倍规则
		roomtype.put("roomType", 0); //房间类型
		roomtype.put("clubid", 0);
		String[] strs = null,strs1 = null;
		if(((String) jsonObject.get("specialcard")).length()!=0){
			strs =  ((String) jsonObject.get("specialcard")).split("-");
		}
		if(((String) jsonObject.get("hoptions")).length()!=0){
			strs1 =   ((String) jsonObject.get("hoptions")).split("-");
		}
		//把信息放到房间
		return addroom(roomtype,rooms,strs,strs1);

	}

	/*
	 *@Author:ZhaoQi
	 *@methodName:初始化一个机器人
	 *@Params:
	 *@Description:
	 *@Return:
	 *@Date:2019/3/12
	 */
	private static UserBean getAiPlayer() {
		UserBean user = new UserBean();
		user.setBunko(0);
		user.setIsReady(0);
		//		user.setPosition(1);
		user.setSession(null);
		user.setState(3);
		user.setType(1);
		user.setWinNumber(0);
		user.setMoney(10000);
		//user.setBetList(new Random().nextInt(4)+1);
		user.setMultiple(new Random().nextInt(4));
		user.setWximg(String.valueOf(new Random().nextInt(10)));
		user.setWxname(String.valueOf(new Random().nextInt(10)));
		user.setIsOwner(-1);
		user.setUserCards(new ArrayList<Integer>());
		return user;
	}

	/*
	 *@Author:ZhaoQi
	 *@methodName:获取下一个操作人的位置
	 *@Params:
	 *@Description:
	 *@Return:
	 *@Date:2019/2/14
	 */
	public static int getPostion(Integer position) {
		switch (position){
		case 1:
			return 2;
		case 2:
			return 3;
		case 3:
			return 1;
		}
		return 0;
	}

	/*
	 *@Author:ZhaoQi
	 *@methodName:加入房间
	 *@Params:
	 *@Description:
	 *@Return:
	 *@Date:2019/2/14
	 */
	public static Msg joinRoom(Map<String, RoomsParam> rooms, RoomsParam roomsParam, UserBean user) {
		Msg msgs = null;
		Lock lock = roomsParam.getLock();
		lock.lock();
		for (RoomsParam rParam : rooms.values()) {
			if(rParam.getUsers().get(String.valueOf(user.getId())) != null){
				msgs = new Msg(320,"玩家还在其他房间无法加入新游戏",null,"joinroom");
				lock.unlock();
				return msgs;
			}
		}
		lock.unlock();
		return msgs;
	}


	/*
	 *@Author:ZhaoQi
	 *@methodName:获取一个房间内的随机位置
	 *@Params:
	 *@Description:
	 *@Return:
	 *@Date:2019/2/14
	 */
	public static Integer givePostions(RoomsParam myRoom) {
		List<Integer> postions = myRoom.getPostions();
		Collections.sort(postions);
		System.out.println("postions"+postions.toString());
		Integer postion = postions.get(0);
		return postion;

	}

	/*
	 *@Author:ZhaoQi
	 *@methodName:判断房间内玩家是否全部准备
	 *@Params:
	 *@Description:
	 *@Return:
	 *@Date:2019/2/15
	 */
	public static boolean isReady(RoomsParam MyRoom) {
		Map<String, UserBean> users = MyRoom.getUsers();
		Lock lock = MyRoom.getLock();
		lock.lock();
		Iterator<Map.Entry<String, UserBean>> die = users.entrySet().iterator();
		int i = 0;
		while(die.hasNext()) {
			Map.Entry<String, UserBean> poeo = die.next();
			if(poeo.getValue().getIsReady()==null||poeo.getValue().getIsReady()==0){
				lock.unlock();
				return false;
			}
			i++;
		}
		if(i>=3){
			lock.unlock();
			return true;
		}else{
			lock.unlock();
			return false;
		}
	}

	/*
	 *@Author:ZhaoQi
	 *@methodName:发牌
	 *@Params:
	 *@Description:
	 *@Return:
	 *@Date:2019/2/15
	 */
	public static RoomsParam sendCards(RoomsParam myRoom) {
		Map<String,Object> map = new HashMap<>();
		Msg msgs;
		List<Integer> cards = myRoom.getRoomCards();
		Map<String, UserBean> users = myRoom.getUsers();
		Iterator<Map.Entry<String, UserBean>> it = users.entrySet().iterator();
		while (it.hasNext()){
			Map.Entry<String, UserBean> poeo = it.next();
			if(poeo.getValue().getType() != 0 && poeo.getValue().getType() != 3 ){
				if(poeo.getValue().getUserCards().size() == 4 ){
					if(myRoom.getRoomType().get("gameType") == 1){
						cards.add(52);
						cards.add(53);
					}
					Random random = new Random();
					int n = random.nextInt(cards.size());
					Integer card = cards.get(n);
					//从一副牌中随机取一张牌
					poeo.getValue().getUserCards().add(card);//将这张牌存入当前用户的牌中
					cards.remove(n);//将这张牌从这副牌中移
					List<Integer> userCards = poeo.getValue().getUserCards();
					poeo.getValue().setUserCards(userCards);
				}else if(poeo.getValue().getType()==1 || poeo.getValue().getType()==2){//如果是参战或者掉线的才发牌
					for (int i = 0; i < 4; i++) {
						Random random = new Random();
						int n = random.nextInt(cards.size());
						Integer card = cards.get(n);//从一副牌中随机取一张牌
						poeo.getValue().getUserCards().add(card);//将这张牌存入当前用户的牌中
						cards.remove(n);//将这张牌从这副牌中移除
					}
					List<Integer> userCards = poeo.getValue().getUserCards();
					poeo.getValue().setUserCards(userCards);
				}
			}
		}
		return myRoom;
	}

	/*
	 *@Author:ZhaoQi
	 *@methodName:初始化用户
	 *@Params:
	 *@Description:
	 *@Return:
	 *@Date:2019/2/12
	 */
	public static UserBean InitializeUser(UserBean user){
		user.setBunko(null);
		user.setIsReady(0);
		user.setPosition(null);
		user.setSession(null);
		user.setMoney(0);
		user.setWximg(null);
		user.setWxname(null);
		user.setId(null);
		user.setIsOwner(-1);
		user.setUserCards(new ArrayList<Integer>());
		return user;
	}

	/*
	 *@Author:ZhaoQi
	 *@methodName:查询房间内所有用户
	 *@Params:[die]
	 *@Description:
	 *@Return:java.util.List<java.lang.String>
	 *@Date:2018/12/27
	 */
	public static Map<String, UserBean> selectRoomUser(RoomsParam rooms) {
		Map<String, UserBean> userMap = rooms.getUsers();
		Iterator<Map.Entry<String, UserBean>> it = userMap.entrySet().iterator();
		Map<String, UserBean> newUser = new HashMap<>();
		while(it.hasNext()){
			Map.Entry<String, UserBean> user = it.next();
			newUser.put(String.valueOf(user.getValue().getId()), user.getValue().getCustom());

		}
		return newUser;
	}
	/**
	* @description :只有坐下的
	* @param rooms 
	* @date : 2019/11/11 20:28
	* @author : jj
	*/
	public static List<UserBean> selectRoomUserType(RoomsParam rooms) {
		Map<Integer, List<UserBean>> collect = rooms.getUsers().values().stream().collect(Collectors.groupingBy(UserBean::getType));
		List<UserBean> userBeans = collect.get(1);
		return userBeans;
	}
	/**
	 * 查询游戏开始不等于0的用户和没有开始等于1、2的用户
	 * @param rooms
	 * @return
	 *//*
	public static Map<String, UserBean> selectRoomUserType(RoomsParam rooms) {
		Map<String, UserBean> userMap = rooms.getUsers();
		Iterator<Map.Entry<String, UserBean>> it = userMap.entrySet().iterator();
		Map<String, UserBean> newUser = new HashMap<>();
		while(it.hasNext()){
			Map.Entry<String, UserBean> user = it.next();
			if(rooms.getIsStart() >=1){
				if(user.getValue().getType() != 0){
					newUser.put(String.valueOf(user.getValue().getId()), user.getValue().getCustom());
				}
			}else{
				if(user.getValue().getType() == 1 || user.getValue().getType() == 2){
					newUser.put(String.valueOf(user.getValue().getId()), user.getValue().getCustom());
				}
			}

		}
		return newUser;
	}*/
	/**
	 * 查询房间内的参战用户
	 * @param rooms
	 * @return
	 */
	public static Map<String, UserBean> selectRoomUserTypes(RoomsParam rooms) {
		Map<String, UserBean> userMap = rooms.getUsers();
		Iterator<Map.Entry<String, UserBean>> it = userMap.entrySet().iterator();
		Map<String, UserBean> newUser = new HashMap<>();
		while(it.hasNext()){
			Map.Entry<String, UserBean> user = it.next();
			if(user.getValue().getType() == 1 || user.getValue().getType() == 2){
				newUser.put(String.valueOf(user.getValue().getId()), user.getValue().getCustom());
			}
		}
		return newUser;
	}

	/*
	 *@Author:ZhaoQi
	 *@methodName:生成一副牌
	 *@Params:
	 *@Description:
	 *@Return:
	 *@Date:2018/11/30
	 */
	public static List<Integer> getCards(Integer type) {

		List<Integer> Cards = new ArrayList<>();
		if (type>0){
			for (int i = 0;i<52;i++){
				Cards.add(i);
			}
		}else {
			for (int i = 0;i<20;i++){
				Cards.add(i);
			}
		}
		System.out.println(Cards);
		return Cards;
	}


	/*
	 *@Author:ZhaoQi
	 *@methodName:返回位置数组
	 *@Params:
	 *@Description:
	 *@Return:
	 *@Date:2019/2/27
	 */
	public static Integer[] getPostion(RoomsParam room,int num) {
		Map<String, UserBean> users = room.getUsers();
		Integer [] arr = new Integer[num];
		int t = 0;
		for(int i = 0 ;i < arr.length ; i++)
			arr[i] = 0;
		Iterator<Map.Entry<String, UserBean>> iterator = users.entrySet().iterator();
		while(iterator.hasNext()){
			Map.Entry<String, UserBean> has = iterator.next();
			if(has.getValue().getType()!=0){
				if(has.getValue().getPosition()!=null){
					arr[has.getValue().getPosition()-1] = Integer.valueOf(String.valueOf(has.getValue().getId()));
				}
			}
		}
		return arr;
	}

	/*
	 *@Author:ZhaoQi
	 *@methodName:获取用户集合中参战或者观战的玩家
	 *@Params:
	 *@Description:
	 *@Return:
	 *@Date:2019/3/11
	 */
	public static Map<String, UserBean> getUsers(RoomsParam myRoom,int type) {
		Map<String, UserBean> users = myRoom.getUsers();
		Map<String, UserBean> users1 = new HashMap<>();
		for (UserBean u:users.values()) {
			if(type == 1){
				if(u.getType()==type || u.getType()==2){//2属于掉线用户  也算参战玩家
					users1.put(String.valueOf(u.getId()),u);
				}
			}else{
				if(u.getType()==type){
					users1.put(String.valueOf(u.getId()),u);
				}
			}
		}
		return users1;
	}
	/**
	 * 修改俱乐部用户积分
	 * @param user
	 * @param myRoom
	 */
	public static void editintergral(UserBean user , RoomsParam myRoom){
		ClubUser clubUser = new ClubUser();
		ClubUser user1 = clubUser.selectOne(new EntityWrapper<ClubUser>().eq("clubName", myRoom.getClubName()).eq("userid", user.getId()));
		user1.setIntegral(user.getMoney());
		user1.updateById();
	}
	/**
	 * 加入俱乐部房间
	 * @param rooms
	 * @param user
	 * @param roomsParam
	 * @return
	 */
	public static Msg joincRoom(Map<String, Game_club> rooms, UserBean user, RoomsParam roomsParam) {
		Msg msgs = null;
		Lock lock = roomsParam.getLock();
		lock.lock();
		if(roomsParam!= null && roomsParam.getRoomType().get("roomType") == 1){
			ClubUser clubUsers = new ClubUser();
			ClubUser us = clubUsers.selectOne(new EntityWrapper<ClubUser>().eq("clubName", roomsParam.getClubName()).eq("userid", user.getId()));
			if(us == null){
				msgs = new Msg(961,"不在俱乐部内", null,"joinroom");
				lock.unlock();
				return msgs;
			}
		}
		for (Game_club game_club : rooms.values()) {
			for (RoomsParam room : game_club.getClubs().values()) {
				if(room.getUsers().get(user.getId()) != null){
					msgs = new Msg(320,"玩家还在其他房间无法加入新游戏",null,"joinroom");
					lock.unlock();
					return msgs;
				}
			}
		}
		lock.unlock();
		return msgs;
	}
	/**
	 * 时间格式
	 * @param time
	 * @return
	 */
	public static String gettime(long time){
		Date date = new Date(time);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(date);
	}

	/**
	 * 判断用户身上的钻石是否够创建房间
	 * @param num
	 * @param user
	 * @param money
	 * @return
	 */
	public static Msg judgediamond(int num ,UserBean user ,int money){
		Msg msgs = null ;
		Game game = new Game();//查询对应局数消耗的钻石数
		Game game2 = game.selectOne(new EntityWrapper<Game>().eq("game_num", num));
		/*if(user.getDiamond() > game2.getPay_num()){//用户的钱大于 创建房间消耗的
			money = game2.getPay_num();
		}else{
			msgs = new Msg(100,"房卡不足，创建失败",null,"createRoom");
		}*/
		return msgs;
	}
	/**
	 * 把信息放到房间
	 * @param roomtype
	 * @param rooms
	 * @param strs
	 * @param strs1
	 * @return
	 */
	public static RoomsParam addroom(Map<String, Integer> roomtype, Map<String, RoomsParam> rooms, String[] strs, String[] strs1){
		RoomsParam room = new RoomsParam();
		List<Integer> postions = new ArrayList<>();
		for(int i = 1;i<=roomtype.get("personnum");i++){
			postions.add(i);
		}
		/*//判断是否包含王牌
		if(roomtype.get("gameType") == 2){
			room.setRoomCards(gameLogic.getCards(1));
		}else{
			room.setRoomCards(gameLogic.getCards(0));
		}*/
		room.setHoptions(strs1);
		room.setSpecialcard(strs);
		room.setRoomName(roomtype.get("roomnum")+"");
		room.setUsers(new HashMap<String, UserBean>());
		room.setLock(new ReentrantLock());
		room.setTalkNum(0);
		room.setIsUp(null);
		room.setIsStart(0);
		room.setGameId(0);
		room.setRoomType(roomtype);
		room.setPostions(postions);
		room.setGametype(0);

		rooms.put(roomtype.get("roomnum")+"",room);
		return room;
	}
	/**
	 * 初始化用户
	 * @param user
	 */
	public static void initializeUser(UserBean user){
		user.setUserCards(new ArrayList<Integer>());
		user.setWinNumber(0);
		user.setSumWinnumber(0);
		user.setIsReady(0);
		user.setOpenCards(0);
		user.setOpentionType(0);
		user.setBetList(new HashMap<>());
	}
	/**
	 * 创建房间返回数据
	 * @param data
	 * @param jsonObject
	 * @param myRoom
	 * @param user
	 * @return
	 */
	public static Map<String, Object> returnMap(Map<String, Object> data,JSONObject jsonObject,RoomsParam myRoom,UserBean user){
		data.put("dqnum", 0);
		data.put("points",(Integer) jsonObject.get("points"));
		data.put("num", (Integer) jsonObject.get("num"));
		data.put("roomType", (Integer) jsonObject.get("roomType"));
		data.put("roomName",myRoom.getRoomName());
		data.put("personnum", jsonObject.get("personnum"));
		data.put("userType", user.getType());
		data.put("gameType",  jsonObject.get("gameType"));
		if(myRoom.getHoptions() != null && Arrays.asList(myRoom.getHoptions()).contains("0")){
			data.put("rubcard", 0);
		}else{
			data.put("rubcard", 1);
		}
		RoomParam re = new RoomParam();
		re.setCreateTime(new Date());
		re.setFounder(myRoom.getFounder());
		re.setRoomId(Long.valueOf(myRoom.getRoomName()));
		re.setGameType(0);
		re.setParam("{\"roomName\":"+Integer.valueOf(myRoom.getRoomName())+",\"num\":"+ myRoom.getRoomType().get("num")+",\"points\":"+myRoom.getRoomType().get("points")+"/"+myRoom.getRoomType().get("points")*2+"}");
		re.insert();
		return data;
	}
	/**
	 * 返回数据
	 * @param data
	 * @param myRoom
	 * @param str
	 * @return
	 */
	public static Map<String, Object> returnMap(Map<String, Object> data,RoomsParam myRoom,String str){

		String[] strings = str.split("-");
		for (String string : strings) {
			if (string.equals("postions")){
				data.put("postions",myRoom.getPostions());
			}
			if(string.equals("roomName")){
				data.put("roomName", myRoom.getRoomName());
			}
			if(string.equals("gameType")){
				data.put("gameType", myRoom.getGametype());
			}
			if(string.equals("roomCards")){
				data.put("roomCards", myRoom.getRoomCards());
			}
			if(string.equals("roomGrade")){
				data.put("roomGrade", myRoom.getRoomGrade());
			}
			if (string.equals("roomPoints")){
				data.put("roomPoints",myRoom.getRoomPoints());
			}
			if(string.equals("bankerMoney")){
				data.put("bankerMoney", myRoom.getBankerMoney());
			}
			if(string.equals("isUp")){
				data.put("isUp", myRoom.getIsUp());
			}
			if (string.equals("isStart")){
				data.put("isStart" , myRoom.getIsStart());
			}
			if(string.equals("setupTime")){
				data.put("setupTime", myRoom.getRoomType().get("setupTime"));
			}
			if(string.equals("robsTime")){
				data.put("robsTime", myRoom.getRoomType().get("robsTime"));
			}
			if(string.equals("bettonTime")){
				data.put("bettonTime", myRoom.getRoomType().get("bettonTime"));
			}
			if(string.equals("brightBrandTime")){
				data.put("brightBrandTime", myRoom.getRoomType().get("brightBrandTime"));
			}

		}
		return data;

	}
	/**
	 * 用户身上的参数返回
	 * @param data
	 * @param user
	 * @param str
	 * @return
	 */
	public static Map<String, Object> returnMap(Map<String, Object> data,UserBean user,String str){
		String[] strings = str.split("-");
		for (String string : strings) {
			if(string.equals("userid")){
				data.put("userid", user.getId());
			}
			if(string.equals("multiple")){
				data.put("multiple", user.getMultiple());
			}
			if(string.equals("bet")){
				data.put("bet", user.getBetList());
			}
			if(string.equals("usercard")){
				data.put("usercard", user.getUserCards());
			}
		}

		return data;
	}


	/**
	 * 查询用户
	 * @param userid
	 * @return
	 */
	public static User getuser(long userid){
		User user = new User();
		user.setId(userid);
		User user2 = user.selectById();
		if(user2!=null){
			return user2;
		}
		return null;
	}
	/**
	 * 清除房间人
	 * @param room
	 */
	public static void removeRoom(RoomsParam room){
		Map<String, UserBean> users = new HashMap<String, UserBean>();
		users.putAll(room.getUsers());
		if(room.getRoomType().get("roomType") == 1){
			for (UserBean u : users.values()) {
				room.getUsers().remove(u.getId()+"");
			}
		}else{
			for (UserBean u : users.values()) {
				room.getUsers().remove(u.getId()+"");
			}
			WebSocketBull.rooms.remove(room.getRoomName());
		}
	}

	/**
	 * 开始游戏初始化
	 * @param myRoom
	 * @param msgs
	 * @param ws 
	 * @return
	 */
	public static Msg startGame(RoomsParam myRoom,Msg msgs, WebSocketBull ws){
		
		myRoom.setIsStart(0);//开始状态
		myRoom.setTalkNum(0);//开牌人数
		myRoom.setAgreenum(0);//同意人数
		myRoom.setPreparenum(0);
		myRoom.setTalkNum(0);//把开牌人数初始化
	/*	if(myRoom.getRoomType().get("gameType") == 2){//判断发牌
			myRoom.setRoomCards(gameLogic.getCards(1));//1 包含王癞
		}else{
			myRoom.setRoomCards(gameLogic.getCards(0));
		}*/
		Map<String , Object> map;
		Map<String, UserBean> users = getUsers(myRoom, 1);//获取用户集合中参战或者观战的玩家
		Map<String,UserBean> users1 = new HashMap<String, UserBean>();
		users1.putAll(users);
		for (UserBean user : users1.values()) {
			if(user.getType() == 0){
				continue;
			}
			if(user.getType() == 3){
				user.setType(1);//用户中途加入开始游戏改成参战
			}
			initializeUser(user);//初始化用户
			if(myRoom.getRoomType().get("roomType") == 1){
				if(user.getMoney() <=0){
					map = new HashMap<>();
					map.put("type", 1);
					map.put("exituserid", user.getId());
					map.put("userName",user.getWxname());
					msgs = new Msg(444,"房间不允许负分，"+user.getWxname()+"退出游戏", map,"Exitgame");
					try {
						ws.broadcast(msgs, myRoom);
					} catch (Exception e) {
						e.printStackTrace();
					}
					myRoom.getPostions().add(user.getPosition());//用户位置 归还房间 删除用户
					users.remove(String.valueOf(user.getId()));
				}
			}
		}
		if(users.size() >= 2){
			myRoom.setIsStart(1);
			map = new HashMap<>();
			map.put("timer", 10);
			map.put("maxz", myRoom.getRoomType().get("maxz"));
			msgs = new Msg(366,"开始新一局", map,"newgame");
		}else{
			myRoom.setIsStart(0);
			msgs = new Msg(388,"玩家退出游戏，人数不够，请等待", null,"newgame");
		}
		return msgs;
	}


	/**
	 * 每个用户应该输赢的 钱数
	 * @param room
	 * @return
	 */
	public static int getMoney(RoomsParam room){
		UserBean zhuangjia = room.getUsers().get(room.getIsUp()+"");//获取庄家
		int sumMoney = 0;
		int money;
		for (UserBean user : room.getUsers().values()) {
			if(zhuangjia.getWinNumber() >0 && zhuangjia.getWinNumber() > zhuangjia.getMoney()){//庄家赢钱 并且 赢 的钱大于自己身上的钱
				if(user.getWinNumber() < 0){
					money = Math.abs(user.getWinNumber())/zhuangjia.getWinNumber()*zhuangjia.getMoney();//按比例
					if(money >= user.getMoney()){
						user.setWinNumber(-user.getMoney());
					}else{
						user.setWinNumber(-money);
					}

				}
			}else if(zhuangjia.getWinNumber() > 0 && zhuangjia.getWinNumber() <= zhuangjia.getMoney()){//庄家赢并且小于自己身上的钱
				if(user.getWinNumber()<0){//输的玩家钱时候够
					if(Math.abs(user.getWinNumber())>=user.getMoney()){
						user.setWinNumber(-user.getMoney());
					}
				}
			}else if(zhuangjia.getWinNumber() < 0 && Math.abs(zhuangjia.getWinNumber())>=zhuangjia.getMoney()){//庄家输 钱并大于自己身上的
				if(user.getWinNumber() > 0){
					money = user.getWinNumber()/zhuangjia.getWinNumber()*zhuangjia.getMoney();
					user.setWinNumber(money);
				}else{
					if(Math.abs(user.getWinNumber())>=user.getMoney()){
						user.setWinNumber(-user.getMoney());
					}
				}
			}else{
				if(user.getWinNumber()<0){
					if(Math.abs(user.getWinNumber())>=user.getMoney()){
						user.setWinNumber(-user.getMoney());
					}
				}
			}
			if(user.getId()!=room.getIsUp()){
				sumMoney += user.getWinNumber();
			}

		}

		return sumMoney;
	}


	public static RoomsParam getclubRoom(JSONObject jsonObject){
		String roomName = (String) jsonObject.get("roomName");//房间号
		String clubid = String.valueOf(jsonObject.get("clubid"));
		return null;
	}
	
	
	/**
	 * 获取用户准备信息
	 * @param myRoom
	 * @return
	 */
	public static List<Object> getuserinfo(RoomsParam myRoom){
		Map<String , Object> map ;
		List<Object> list = new ArrayList<Object>();
		for (UserBean user : myRoom.getUsers().values()) {
			if(user.getType() != 0){
				map = new HashMap<String, Object>();
				list.add(user.getCustom());
			}
		}
		return list;
		
	}
	

}
